<?php

namespace App\Http\Requests\Cms;

use Illuminate\Foundation\Http\FormRequest;

class MessageSendRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if ($this->isMethod('post')){
            return [
                'to_user'=>['required','text_rule'],
                'title'=>'required|between:2,20|text_rule',
                'content'=>'required|between:10,250|text_rule',
            ];
        }
        return [];
    }

    public function attributes()
    {
        return [
            'to_user'=>'接受人',
            'title'=>'留言主题',
            'content'=>'留言内容',
        ];
    }

    public function messages()
    {
        return [
            'required'=>':attribute不能为空',
            'text_rule'=>':attribute包含非法字符',
            'between'=>':attribute长度必须在:min到:max之间'
        ];
    }
}
